<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isfullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="screenfull" />
  </div>
</template>

<script>
// cnpm i screenfull@5.2.0 -S  插件
// 下包-导入插件-实现全屏逻辑
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isfullscreen: false // 是否显示全屏
    }
  },
  mounted() {
    screenfull.on('change', () => {
      this.isfullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    // 切换全屏
    screenfull() {
      // 当点击全屏图标时，true
      this.isfullscreen = true
      // 调用 插件提供的 toggle 方法，实现切换全屏
      screenfull.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
